package HelloSeries.ui.prefs.elems.flextables.view;

import java.awt.GridLayout;

import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableColumn;

import HelloSeries.ui.prefs.elems.flextables.editor.ConfEditor;
import HelloSeries.ui.prefs.elems.flextables.model.FlexTableConfModel;
import HelloSeries.ui.prefs.elems.flextables.renderer.DefaultSwingRenderer;

public class FlexTableConf extends JPanel{

	private FlexTableConfModel model;
	private JTable table;

	public FlexTableConf() {
		super(new GridLayout(1,0));
		this.model = new FlexTableConfModel();
		this.table = new JTable (model);
		setTableProperties(table);
		initRenderers(table);
		initColumnSizes();
		this.add(table);
	}

	private void setTableProperties(JTable table) {
		table.setShowGrid(false);
		table.setRowSelectionAllowed(false);
		table.setCellSelectionEnabled(false);
		table.setPreferredScrollableViewportSize(table.getPreferredSize());
		table.setFocusable(false);
		table.setRowHeight(25);
		table.setBackground(null);
	}
	public void initRenderers(JTable table){
		table.setDefaultRenderer(JTextField.class, new DefaultSwingRenderer());
		table.getColumn("B").setCellEditor(new ConfEditor());
	}
	
	private void initColumnSizes() {
		FlexTableConfModel model = (FlexTableConfModel)table.getModel();
		TableColumn column1 = table.getColumnModel().getColumn(0);
		TableColumn column2 = table.getColumnModel().getColumn(1);
		column1.setPreferredWidth(100);
		column2.setPreferredWidth(15);
	}

	public FlexTableConfModel getModel() {
		return model;
	}

	public void setModel(FlexTableConfModel model) {
		this.model = model;
	}

	public JTable getTable() {
		return table;
	}

	public void setTable(JTable table) {
		this.table = table;
	}
	
}
